package demo7;
import java.util.Arrays;
import java.util.Comparator;
public class test {

    public static void main(String[] args) {

    }


    public static void main7(String[] args) {
        Integer[] arr={1,2,3,4,5,6,7};
        Integer[] arr2={1,2,3,4,5,6,7};
        boolean equal1=Arrays.equals(arr,arr2);
        System.out.println(equal1);
    }


    public static void main6(String[] args) {
        Integer[] arr={1,2,3,4,5,6,7};
        Arrays.fill(arr,99);
        System.out.println(Arrays.toString(arr));
    }


    public static void main5(String[] args) {
        Integer[] arr={1,2,3,4,5,6,7};
        Integer[] arr2=Arrays.copyOf(arr,arr.length);
        Integer[] arr4=Arrays.copyOf(arr,arr.length+1);
        Integer[] arr3=Arrays.copyOf(arr,arr.length-1);
        System.out.println(Arrays.toString(arr2));
    }


    public static void main4(String[] args) {
        Integer[] arr={1,2,3,4,5,6,7};
        int index=Arrays.binarySearch(arr,8);
        System.out.println(index);
    }






    public static void main3(String[] args) {
        int[] arr={-1,1,8,0,20};
        //bubble(arr);
        bubble02(arr, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                int i1=(Integer) o1;
                int i2=(Integer) o2;
                return i2-i1;
            }
        });
        System.out.println(Arrays.toString(arr));
    }
//    public static void bubble(int[] arr){
//        for(int i=0;i<arr.length;i++){
//            for(int j=0;j<arr.length-1-i;j++){
//                if(arr[j]>arr[j+1]){
//                    int temp=arr[j];
//                    arr[j]=arr[j+1];
//                    arr[j+1]=temp;
//                }
//            }
//        }
    public static void bubble02(int[] arr, Comparator c){
        for(int i=0;i<arr.length;i++){
            for(int j=0;j<arr.length-1-i;j++){
                //数组排序有这个c.compare(arr[j],arr[j+1])返回值决定
                if(c.compare(arr[j],arr[j+1])>0){
                    int temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
    }
}
